<?php

class Users_RegistrationController extends Lizard_Core_Controller_Action
{
    /**
     * Register
     *
     */
    public function indexAction()
    {
        $form = $this->getForm('Registration');

        if ($this->_request->isPost()) {

            if ($form->isValid($this->_getAllParams()) ) {
                $row = $this->getTable()->createRow();
                $row->setFromArray($form->getValues());
                $row->save();

                $alert = new Lizard_Alerts_Type_Success();
                $alert->message = 'Now you\'re registered!';
                $alert->save();

                $this->_redirect('/');
            }
        }
        $this->view->form = $form;
    }

    /**
     * Confirms registration
     *
     */
    public function confirmAction()
    {
        $this->_helper->viewRenderer->setNoRender();
        $this->_helper->layout()->disableLayout();

        if ($hash = $this->_getParam('hash')) {
            if ($this->getTable()->confirmRegistration($hash)) {

                $alert = new Lizard_Alerts_Type_Success();
                $alert->message = 'Now you\'re confirm your registration! Please log in now';
                $alert->save();

                $this->_redirect('/login');

            } else {
                $alert = new Lizard_Alerts_Type_Error();
                $alert->message = 'The user with specified data not found! Possibly you\'re already confirmed your registration';
                $alert->save();
            }
        }
        $this->_redirect('/');
    }
}